<?php
/**
 * Created by PhpStorm.
 * User: extraxue
 * Date: 2018/5/1
 * Time: 下午10:20
 */

$deptId=$_POST['deptId'];
$deptName=$_POST['deptName'];
$deptLeaderName=$_POST['deptLeaderName'];
$deptPhone=$_POST['deptPhone'];
$remark=$_POST['remark'];

require_once('pdo.php');

$sqlCheckDeptIdIsHave="select * from dept_info a where a.dept_id = '{$deptId}'";
$rsCheckDeptIdIsHave=$pdo->query($sqlCheckDeptIdIsHave);
$resultCheckDeptIdIsHave=$rsCheckDeptIdIsHave->fetch(PDO::FETCH_ASSOC);

$sqlCheckDeptNameIsHave="select * from dept_info a where a.dept_name = '{$deptName}'";
$rsCheckDeptNameIsHave=$pdo->query($sqlCheckDeptNameIsHave);
$resultCheckDeptNameIsHave=$rsCheckDeptNameIsHave->fetch(PDO::FETCH_ASSOC);


if(!$resultCheckDeptIdIsHave && !$resultCheckDeptNameIsHave){
    $sqlAddDept="insert into dept_info (dept_id, dept_name, dept_leader, dept_phone, remark) 
values ('{$deptId}','{$deptName}','{$deptLeaderName}','{$deptPhone}','{$remark}')";
    $rsAddDept=$pdo->exec($sqlAddDept);
    echo '<script>alert("添加成功！");history.back();</script>';

}else{
    echo '<script>alert("此党支部ID或党支部名称已被使用，请核实后重新填写");history.back();</script>';
}
